{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "cd ../src/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from rubik import *"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "参数 `min_scale, max_scale, num_step` 可根据魔方大小修改，默认参数为\n",
    "\n",
    "```py\n",
    "import scale_match\n",
    "scale_match.min_scale = 0.8\n",
    "scale_match.max_scale = 3\n",
    "scale_match.num_step = 50\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 1-求解魔方"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 魔方初始化，设置操作的时间间隔\n",
    "cube = Cube(interval=0.2)\n",
    "\n",
    "# 检查识别是否准确\n",
    "# 注意：弹出窗口按空格键关闭，不要点右上角的 ×\n",
    "cube.show_dectition() \n",
    "\n",
    "# 检查鼠标位置是否正确\n",
    "# cube.check_facets(sides=[0]) \n",
    "\n",
    "# 检验基本旋转\n",
    "# cube.check_basic_moves()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 识别并求解魔方\n",
    "cube.auto_solve_cube(wait=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2-构造魔方"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from tools import expand_cube\n",
    "txt = \"UBRLUFFUBLRUFRLLLRDBDRFDBBUDDBUDDLRFBFLDLBFFRFLRUBRDUU\"\n",
    "state = input(f\"请输入魔方状态的代码，直接回车使用示例代码\\n示例：\\n{txt}\\n\")\n",
    "if not state: state = txt\n",
    "try:\n",
    "    kb.solve(state) # 检验是否有效\n",
    "except:\n",
    "    print(\"魔方代码输入有误！请检查\")\n",
    "    print(expand_cube(state))\n",
    "print(\"输入魔方的展开图如下\")\n",
    "print(expand_cube(state))\n",
    "\n",
    "cube = Cube()\n",
    "\n",
    "input(\"按回车，开始构造给定魔方：\")\n",
    "sol = cube.to_cube_state(state)\n",
    "print(\"魔方解法为\")\n",
    "for i in sol:\n",
    "    print(i,end=\"\\t\")"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "916dbcbb3f70747c44a77c7bcd40155683ae19c65e1c03b4aa3499c5328201f1"
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
